package be.dch.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import be.dch.gui.layout.MyTabbedPaneUI;
import be.dch.gui.panels.AbstractPanel;
import be.dch.gui.panels.HelpPanel;
import be.dch.gui.panels.MainPanel;
import be.dch.gui.panels.OptionPanel;
import be.dch.gui.panels.OutputPanel;
import be.dch.gui.panels.Srtm2OsmPanel;
import be.dch.gui.panels.TypEditorPanel;

public final class GarminMapGuiWindow extends JFrame {

    /** * */
    private static final long serialVersionUID = -2564229549948347654L;

    private static GarminMapGuiWindow gui = new GarminMapGuiWindow();
    private final transient JTabbedPane tabbedContainer;

    public static GarminMapGuiWindow getInstance() {

	return GarminMapGuiWindow.gui;
    }

    /**
     * Method used build the main window.
     * 
     */
    private GarminMapGuiWindow() {
	super();
	this.setTitle("Garmin Map GUI v0.1 (c) DCH");
	this.setBackground(Color.gray);
	this.setSize(800, 600);
	this.setResizable(false);
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	final Toolkit toolkit = Toolkit.getDefaultToolkit();
	final Dimension screenSize = toolkit.getScreenSize();
	final int x = (screenSize.width - this.getWidth()) / 2;
	final int y = (screenSize.height - this.getHeight()) / 2;
	this.setLocation(x, y);

	this.tabbedContainer = new JTabbedPane(SwingConstants.RIGHT);
	this.tabbedContainer.setUI(new MyTabbedPaneUI());
	this.addAbstractPanel(MainPanel.getInstance());
	this.addAbstractPanel(TypEditorPanel.getInstance());
	this.addAbstractPanel(Srtm2OsmPanel.getInstance());
	this.addAbstractPanel(OptionPanel.getInstance());
	this.addAbstractPanel(OutputPanel.getInstance());
	this.addAbstractPanel(HelpPanel.getInstance());

	this.add(this.tabbedContainer);

    }

    private void addAbstractPanel(final AbstractPanel panel) {
	this.tabbedContainer.addTab(panel.getPanelTitle(), panel.getPanelIcon(), panel);
    }

    public void selectTab(final JComponent comp) {
	for (int i = 0; i < this.tabbedContainer.getTabCount(); i++) {
	    this.tabbedContainer.setSelectedComponent(comp);
	}
    }

}
